package com.project.service.impl;

import com.project.bean.StudentBean;
import com.project.mapper.IStudentMapper;
import com.project.service.IStudentService;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class StudentServiceImpl extends BaseService implements IStudentService {
    @Override
    public void addStudent(StudentBean studentBean) {
        SqlSession session = this.getSession();
        IStudentMapper mapper = session.getMapper(IStudentMapper.class);
        mapper.addStudent(studentBean);
        session.commit();
        session.close();
    }

    @Override
    public void delStudent(int id) {
        SqlSession session = this.getSession();
        IStudentMapper mapper = session.getMapper(IStudentMapper.class);
        mapper.delStudent(id);
        session.commit();
        session.close();
    }

    @Override
    public void update(int id, int roomId) {
        SqlSession session = this.getSession();
        IStudentMapper mapper = session.getMapper(IStudentMapper.class);
        mapper.update(id,roomId);
        session.commit();
        session.close();
    }

    @Override
    public StudentBean findById(int id) {
        SqlSession session = this.getSession();
        IStudentMapper mapper = session.getMapper(IStudentMapper.class);
        StudentBean student = mapper.findById(id);
        session.close();
        return student;
    }

    @Override
    public List<StudentBean> findByItem(String name, String stuClass, String stuRoom) {
        SqlSession session = this.getSession();
        IStudentMapper mapper = session.getMapper(IStudentMapper.class);
        List<StudentBean> list = mapper.findByItem(name,stuClass,stuRoom);
        session.close();
        return list;
    }
}
